Ext
		.define(
				'com.hh.global.SimpleGridPanelWindow',
				{
					extend : 'com.hh.base.BaseWindow',
					editPage : null,
					pkey : 'id',
					addText : '新增',
					deleteText : '删除',
					updateText : '修改',
					searchText : '搜索',
					hi_crightMenu : false,
					hi_rightMenu : false,
					hi_add : false,
					hi_update : false,
					hi_delete : false,
					hi_search : false,
					hi_up : true,
					hi_down : true,
					init : function() {
						this.callParent();
						var config = this.config;
						var searchPanelItems = this.getSearchPanelItems();
						var items = [];
						if (searchPanelItems.length > 0) {
							searchPanelItems.push({
								name : 'orgCode',
								xtype : 'widgetComboBoxTree',
								fieldLabel : '组织机构',
								columnWidth : 0.3,
								action : 'usersystem-App-queryCurrOrgTree',
								extraParams : {
									action : this.action + this.gridAction
								}
							});
							items
									.push(this
											.createSearchPanel(searchPanelItems));
						}
						items.push(this.createGrid());
						this.panel.add(items);
					},
					getSearchPanelItems : function() {
						return [];
					},
					getEditPage : function() {
						return this.editPage;
					},
					searchPanelMaxHeighe : null,
					createSearchPanel : function(items) {
						this.searchPabnel = Ext.create(
								'com.hh.base.BaseFormPanel', {
									region : 'north',
									title : '按条件查询',
									items : items,
									height : this.searchPanelMaxHeighe,
									collapsible : true,
									padding : '1 1 1 1',
									collapsed : true,
									buttons : []
								});
						return this.searchPabnel;
					},
					gridListeners : null,
					getGridListeners : function() {
						this.gridListeners;
					},
					setGridListeners : function(gridListeners) {
						this.gridListeners = gridListeners;
					},
					getStoreFields : function() {
						return [ 'id', 'text' ];
					},
					getGridColumns : function() {
						return [ {
							dataIndex : 'id',
							flex : 1,
							hidden : true
						}, {
							text : '名称',
							dataIndex : 'text',
							flex : 1
						} ];
					},
					gridConfig : {},
					createGrid : function() {
						var win = this;
						var fieldList = this.getStoreFields();
						fieldList.push("id", "vorgid", "order", "vcreate");
						var store = this.getStore(fieldList);

						var gridConfig = {
							columns : this.getGridColumns(),
							bbar : this.getTbar(),
							store : store,
							tbar : this.getToolbar(),
							listeners : this.getGridListeners(),
							selModel : Ext
									.create('Ext.selection.CheckboxModel')
						};
						Ext.apply(gridConfig, this.gridConfig);
						if (this.gridOpen == true) {
							Ext.apply(gridConfig, {
								plugins : this.getGridRowPlugins()
							});
						}
						this.grid = Ext.create('com.hh.base.BaseGridPanel',
								gridConfig);
						if (!this.hi_rightMenu) {
							var rightMenu = win.getRightMenu();
							this.grid.on('itemcontextmenu', function(a, b, c,
									d, e) {
								rightMenu.showAt(e.getXY());
								rightMenu.doConstrain();
								e.stopEvent();
							}, win);
						}
						if (!this.hi_crightMenu) {
							var containeRrightMenu = win
									.getContainerRightMenu();
							if (containeRrightMenu != null) {
								this.grid.on('containercontextmenu', function(
										view, e) {
									containeRrightMenu.showAt(e.getXY());
									containeRrightMenu.doConstrain();
									e.stopEvent();
								}, win);
							}
						}

						return this.grid;
					},
					getGridRowPlugins : function() {
						var tpls = [];
						var columns = this.getGridColumns();
						for ( var i = 0; i < columns.length; i++) {
							var column = columns[i];
							if (column.text && column.dataIndex) {
								var tpl = '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b>'
										+ column.text
										+ '：</b> {'
										+ column.dataIndex + '}<br><br>'
								tpls.push(tpl);
							}
						}
						return [ {
							ptype : 'rowexpander',
							rowBodyTpl : tpls
						} ];
					},
					getTbar : function() {
						var page = this;
						this.tbar = Ext.create('com.hh.base.BasePagingToolbar',
								{
									pageSize : static_var.pageSize,
									store : this.store,
									page : page
								});
						return this.tbar;
					},
					gridAction : 'queryPagingData',
					getStore : function(fields, url1) {
						var proxy = ExtStore.getGridStoreProxyByObject({
							url : (url1 == null ? this.action + this.gridAction
									: url1),
							extraParams : this.getExtraParams()
						});
						this.store = Ext.create('com.hh.base.BaseDataStore', {
							pageSize : static_var.pageSize,
							fields : fields,
							proxy : proxy
						});
						return this.store;
					},
					extraParams : {},
					getExtraParams : function() {
						return this.extraParams;
					},
					getGridRecords : function() {
						return this.grid.getSelectionModel().getSelection();
					},
					getGridRecord : function() {
						return this.grid.getSelectionModel().getLastSelected();
					},
					setExtraParams : function(extraParams) {
						this.extraParams = extraParams;
					},
					getToolbarItem : function(type) {
						var panel = this;
						if (type == 'add') {
							return {
								iconCls : 'add',
								text : panel.addText,
								handler : function() {
									panel.doAdd();
								}
							};
						} else if (type == 'delete') {
							return {
								iconCls : 'delete',
								text : panel.deleteText,
								handler : function() {
									panel.doDelete();
								}
							};
						} else if (type == 'update') {
							return {
								iconCls : 'update',
								text : panel.updateText,
								handler : function() {
									panel.doUpdate();
								}
							};
						} else if (type == 'search') {
							return {
								iconCls : 'search',
								text : panel.searchText,
								handler : function() {
									panel.doSearch();
								}
							};
						} else if (type == 'cancel') {
							return {
								iconCls : 'cancel',
								text : '重置查询条件',
								handler : function() {
									panel.searchPabnel.getForm().reset();
								}
							};
						} else if (type == 'up') {
							return {
								iconCls : 'up',
								text : '上移',
								handler : function() {
									panel.orderUp();
								}
							};
						} else if (type == 'down') {
							return {
								iconCls : 'down',
								text : '下移',
								handler : function() {
									panel.orderDown();
								}
							};
						}
					},
					tbaritems : [],
					getTbarItems : function() {
						var toolbarItems = [];
						var page = this;
						if (!page.hi_add) {
							toolbarItems.push(this.getToolbarItem("add"));
						}
						if (!page.hi_update) {
							toolbarItems.push(this.getToolbarItem("update"));
						}
						if (!page.hi_delete) {
							toolbarItems.push(this.getToolbarItem("delete"));
						}
						if (!page.hi_up) {
							toolbarItems.push(this.getToolbarItem("up"));
						}
						if (!page.hi_down) {
							toolbarItems.push(this.getToolbarItem("down"));
						}
						if (!page.hi_search) {
							toolbarItems.push('->');
							toolbarItems.push(this.getToolbarItem("search"));
							if (this.getSearchPanelItems().length > 0) {
								toolbarItems
										.push(this.getToolbarItem("cancel"));
							}
						}
						return toolbarItems;
					},
					getRightMenuItems : function() {
						var page = this;
						var toolbarItems = [];
						if (!page.hi_search) {
							toolbarItems.push(this.getToolbarItem("search"));
						}
						if (!page.hi_add) {
							toolbarItems.push(this.getToolbarItem("add"));
						}
						if (!page.hi_update) {
							toolbarItems.push(this.getToolbarItem("update"));
						}
						if (!page.hi_delete) {
							toolbarItems.push(this.getToolbarItem("delete"));
						}
						if (!page.hi_up) {
							toolbarItems.push(this.getToolbarItem("up"));
						}
						if (!page.hi_down) {
							toolbarItems.push(this.getToolbarItem("down"));
						}
						return toolbarItems;
					},
					getContainerRightMenuItems : function() {
						var page = this;
						var toolbarItems = [];
						if (!page.hi_search) {
							toolbarItems.push(this.getToolbarItem("search"));
						}
						if (!page.hi_add) {
							toolbarItems.push(this.getToolbarItem("add"));
						}
						return toolbarItems;
					},
					getToolbar : function() {
						var panel = this;
						return Ext.create('com.hh.base.BaseToolbar', {
							items : panel.getTbarItems()
						});
					},
					getRightMenu : function() {
						var panel = this;
						this.rightMenu = Ext.create('Ext.menu.Menu', {
							items : panel.getRightMenuItems()
						});

						return this.rightMenu;
					},
					getContainerRightMenu : function() {
						var panel = this;
						this.rightMenu = Ext.create('Ext.menu.Menu', {
							items : panel.getContainerRightMenuItems()
						});

						return this.rightMenu;
					},
					doAdd : function() {
						var editPageUrl = this.getEditPage();
						var page = this;
						var win = ExtUtil.create(editPageUrl,
								{
									id : this.id + '-'
											+ editPageUrl.replace(/\./g, ''),
									parentPanel : this,
									callbackRefresh : function() {
										page.store.load();
									}
								});
						win.show();
					},
					doOperateDelete : function(record) {
						this.doBaseDelete(this.grid, [ record ], this.action
								+ 'deleteByIds');
					},
					doBaseDelete : function(grid, records, url, msg) {
						if (Util.isNull(records)) {
							ExtFrame.msg("请选中要删除的数据！");
						} else {
							var strids = Util.recordsToStrByKey(records,
									this.pkey);
							var vorgids = Util.recordsToStrByKey(records,
									"vorgid");
							var vcreates = Util.recordsToStrByKey(records,
									"vcreate");

							if (Util.isNull(strids)) {
								return;
							}
							var msgStr = '您确认要删除信息吗？,请慎重...';
							if (msg) {
								msgStr = msg;
							}
							var result = Ext.Msg.confirm('请确认',
									'<span style="color:red"><b>提示:</b>'
											+ msgStr + '</span>',
									function(btn) {
										if (btn == 'yes') {
											Request.synRequestObject(url, {
												ids : strids,
												orgids : vorgids,
												vcreates : vcreates
											});
											grid.getStore().load();
										}
									});
						}
					},
					doDelete : function(method, msg) {
						var panel = this;
						var methodAction = 'deleteByIds';
						if (method) {
							methodAction = method;
						}
						var url = panel.action + methodAction;
						var grid = this.grid;
						var records = grid.getSelectionModel().getSelection();
						this.doBaseDelete(grid, records, url, msg);
					},
					doUpdate : function() {
						var page = this;
						var editPageUrl = this.getEditPage();
						var record = this.grid.getSelectionModel()
								.getSelection();
						if (Util.isNull(record)) {
							ExtFrame.msg('请选中要编辑的数据！');
						} else {
							var win = ExtUtil.create(editPageUrl, {
								id : this.id + '-'
										+ editPageUrl.replace(/\./g, ''),
								parentPanel : this,
								parentRecord : record[0],
								callbackRefresh : function() {
									page.store.load();
								}
							});
							win.show();
						}
					},
					doSearch : function() {
						var params = {};
						if (this.searchPabnel != null) {
							var items = this.searchPabnel.getForm().items;
							for ( var i = 0; i < items.length; i++) {
								params[items[i].name] = this.searchPabnel
										.getForm().findField(items[i].name)
										.getValue();
							}
							Ext.apply(this.grid.getStore().proxy.extraParams,
									params);
						}
						this.grid.getStore().load();
					},

					getOperateGridColumn : function() {
						var page = this;
						var editPageUrl = this.getEditPage();
						return {
							text : '操作',
							menuDisabled : true,
							sortable : false,
							xtype : 'actioncolumn',
							width : 50,
							items : [
									{
										iconCls : 'delete',
										tooltip : '删除',
										handler : function(grid, rowIndex,
												colIndex) {
											var rec = grid.getStore().getAt(
													rowIndex);
											page.doOperateDelete(rec);
										}
									},
									{
										iconCls : 'update',
										tooltip : '修改',
										handler : function(grid, rowIndex,
												colIndex) {
											var rec = grid.getStore().getAt(
													rowIndex);
											var win = ExtUtil
													.create(
															editPageUrl,
															{
																id : page.id
																		+ '-'
																		+ editPageUrl
																				.replace(
																						/\./g,
																						''),
																parentPanel : page,
																parentRecord : rec,
																callbackRefresh : function() {
																	page.store
																			.load();
																}
															});
											win.show();
										}
									} ]
						};
					},
					putParam : function(name, value) {
						this[name] = value;
					},
					orderUp : function() {
						var page = this;
						var store = page.grid.getStore();
						var record = page.grid.getSelectionModel()
								.getLastSelected();
						if (Util.isNull(record)) {
							ExtFrame.msg("请选中要下移的数据！");
						} else {
							var index = store.indexOf(record);
							if (index > 0) {
								var recordup = store.getAt(index - 1);
								Request.request(page.action + 'order', {
									id1 : record.get("id"),
									id2 : recordup.get("id"),
									order1 : record.get("order"),
									order2 : recordup.get("order")
								}, function(result) {
									if (result.isSuccess == true) {
										store.removeAt(index);
										record.set("order",recordup.get("order"));
										store.insert(index - 1, record);
										page.grid.getSelectionModel().select(
												index - 1);
									}
								}, {
									isDefaultMsg : true
								});
							} else {
								ExtFrame.msg("已经是第一个了");
							}
						}
					},
					orderDown : function() {
						var page = this;
						var store = page.grid.getStore();
						var record = page.grid.getSelectionModel()
								.getLastSelected();
						if (Util.isNull(record)) {
							ExtFrame.msg("请选中要下移的数据！");
						} else {
							var index = store.indexOf(record);
							if (index < store.getCount() - 1) {
								var recordup = store.getAt(index + 1);
								Request.request(page.action + 'order', {
									id1 : record.get("id"),
									id2 : recordup.get("id"),
									order1 : record.get("order"),
									order2 : recordup.get("order")
								}, function(result) {
									if (result.isSuccess == true) {
										store.removeAt(index);
										record.set("order",recordup.get("order"));
										store.insert(index + 1, record);
										page.grid.getSelectionModel().select(
												index + 1);
									}

								}, {
									isDefaultMsg : true
								});
							} else {
								ExtFrame.msg("已经是最后一个了");
							}
						}
					}
				});